﻿namespace Chain.BLL
{
    using Chain.IDAL;
    using Chain.Model;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Runtime.InteropServices;

    public class PointLog
    {
        private readonly Chain.IDAL.PointLog dal = new Chain.IDAL.PointLog();

        public int Add(Chain.Model.PointLog model)
        {
            return this.dal.Add(model);
        }

        public DataTable AgainPrint(int pointID)
        {
            return this.dal.AgainPrint(pointID);
        }

        public List<Chain.Model.PointLog> DataTableToList(DataTable dt)
        {
            List<Chain.Model.PointLog> list = new List<Chain.Model.PointLog>();
            int count = dt.Rows.Count;
            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    Chain.Model.PointLog item = new Chain.Model.PointLog();
                    if ((dt.Rows[i]["PointID"] != null) && (dt.Rows[i]["PointID"].ToString() != ""))
                    {
                        item.PointID = int.Parse(dt.Rows[i]["PointID"].ToString());
                    }
                    if ((dt.Rows[i]["PointMemID"] != null) && (dt.Rows[i]["PointMemID"].ToString() != ""))
                    {
                        item.PointMemID = int.Parse(dt.Rows[i]["PointMemID"].ToString());
                    }
                    if ((dt.Rows[i]["PointNumber"] != null) && (dt.Rows[i]["PointNumber"].ToString() != ""))
                    {
                        item.PointNumber = int.Parse(dt.Rows[i]["PointNumber"].ToString());
                    }
                    if ((dt.Rows[i]["PointChangeType"] != null) && (dt.Rows[i]["PointChangeType"].ToString() != ""))
                    {
                        item.PointChangeType = int.Parse(dt.Rows[i]["PointChangeType"].ToString());
                    }
                    if ((dt.Rows[i]["PointRemark"] != null) && (dt.Rows[i]["PointRemark"].ToString() != ""))
                    {
                        item.PointRemark = dt.Rows[i]["PointRemark"].ToString();
                    }
                    if ((dt.Rows[i]["PointShopID"] != null) && (dt.Rows[i]["PointShopID"].ToString() != ""))
                    {
                        item.PointShopID = int.Parse(dt.Rows[i]["PointShopID"].ToString());
                    }
                    if ((dt.Rows[i]["PointCreateTime"] != null) && (dt.Rows[i]["PointCreateTime"].ToString() != ""))
                    {
                        item.PointCreateTime = DateTime.Parse(dt.Rows[i]["PointCreateTime"].ToString());
                    }
                    if ((dt.Rows[i]["PointUserID"] != null) && (dt.Rows[i]["PointUserID"].ToString() != ""))
                    {
                        item.PointUserID = int.Parse(dt.Rows[i]["PointUserID"].ToString());
                    }
                    if ((dt.Rows[i]["PointOrderCode"] != null) && (dt.Rows[i]["PointOrderCode"].ToString() != ""))
                    {
                        item.PointOrderCode = dt.Rows[i]["PointOrderCode"].ToString();
                    }
                    if ((dt.Rows[i]["PointGiveMemID"] != null) && (dt.Rows[i]["PointGiveMemID"].ToString() != ""))
                    {
                        item.PointGiveMemID = Convert.ToInt32(dt.Rows[i]["PointGiveMemID"]);
                    }
                    list.Add(item);
                }
            }
            return list;
        }

        public bool Delete(int PointID)
        {
            return this.dal.Delete(PointID);
        }

        public bool DeleteList(string PointIDlist)
        {
            return this.dal.DeleteList(PointIDlist);
        }

        public int DeleteLog(string strOrderAccount)
        {
            return this.dal.DeleteLog(strOrderAccount);
        }

        public bool Exists(int PointID)
        {
            return this.dal.Exists(PointID);
        }

        public bool Exists(string account)
        {
            return this.dal.Exists(account);
        }

        public DataSet GetAllList()
        {
            return this.GetList("");
        }

        public DataSet GetList(string strWhere)
        {
            return this.dal.GetList(strWhere);
        }

        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return this.dal.GetList(Top, strWhere, filedOrder);
        }

        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return this.dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }

        public DataSet GetListSP(int PageSize, int PageIndex, out int resCount, params string[] strWhere)
        {
            return this.dal.GetListSP(PageSize, PageIndex, out resCount, strWhere);
        }

        public int GetMaxId()
        {
            return this.dal.GetMaxId();
        }

        public Chain.Model.PointLog GetModel(int PointID)
        {
            return this.dal.GetModel(PointID);
        }

        public List<Chain.Model.PointLog> GetModelList(string strWhere)
        {
            DataSet list = this.dal.GetList(strWhere);
            return this.DataTableToList(list.Tables[0]);
        }

        public DataSet GetPointByTime(DateTime starttime, DateTime endtime, string strwhere)
        {
            return this.dal.GetPointByTime(starttime, endtime, strwhere);
        }

        public int GetPointChange(string strSql)
        {
            return this.dal.GetPointChange(strSql);
        }

        public int GetPointNumber(string strWhere)
        {
            return this.dal.GetPointNumber(strWhere);
        }

        public int GetRecordCount(string strWhere)
        {
            return this.dal.GetRecordCount(strWhere);
        }

        public bool IsSignedToday(int memId)
        {
            return this.dal.IsSignedToday(memId, 0x10);
        }

        public int MemPointRollback(int memID, int intPointNumber)
        {
            return this.dal.UpdateMemPoint(memID, intPointNumber);
        }

        public bool Update(Chain.Model.PointLog model)
        {
            return this.dal.Update(model);
        }

        public int UpdatePointLog(string strOrderCode, int intPointNumber, int intMemID, string strRemark)
        {
            return this.dal.UpdatePointLog(strOrderCode, intPointNumber, intMemID, strRemark);
        }
    }
}

